Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance LogRecord::add_attributes interface to accept generic Iterables #1741

Merged
merged 6 commits into from
May 11, 2024

Conversation

lalitb
Copy link
Member

@lalitb lalitb commented May 11, 2024

Changes

Modify the add_attributes method in the LogRecord trait to accept any type that implements IntoIterator, for better flexibility and usability. This change allows the method to handle a wider range of input types, including arrays, vectors, hashmap, and other custom collections.

Existing:

fn add_attributes(&mut self, attributes: Vec<(Key, AnyValue)>)

PR:

    fn add_attributes<I, K, V>(&mut self, attributes: I)
    where
        I: IntoIterator<Item = (K, V)>,
        K: Into<Key>,
        V: Into<AnyValue>;

Merge requirement checklist

  • CONTRIBUTING guidelines followed
  • Unit tests added/updated (if applicable)
  • Appropriate CHANGELOG.md files updated for non-trivial, user-facing changes
  • Changes in public API reviewed (if applicable)

@lalitb lalitb requested a review from a team May 11, 2024 19:33
Copy link

codecov bot commented May 11, 2024

Codecov Report

Attention: Patch coverage is 84.78261% with 7 lines in your changes are missing coverage. Please review.

Project coverage is 71.4%. Comparing base (348ec9e) to head (1f33277).
Report is 15 commits behind head on main.

Files Patch % Lines
opentelemetry/src/logs/noop.rs 0.0% 7 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main   #1741     +/-   ##
=======================================
+ Coverage   71.0%   71.4%   +0.3%     
=======================================
  Files        135     136      +1     
  Lines      20751   20880    +129     
=======================================
+ Hits       14746   14915    +169     
+ Misses      6005    5965     -40     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

where
I: IntoIterator<Item = (K, V)>,
K: Into<Key>,
V: Into<AnyValue>;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not adding the default implementation to iteratively call add_attribute in API, let SDK decide how to add the attributes.

Copy link
Contributor

@TommyCpp TommyCpp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Always good to allow people bring their own types

@@ -26,7 +26,11 @@ pub trait LogRecord {
fn set_body(&mut self, body: AnyValue);

/// Adds multiple attributes.
fn add_attributes(&mut self, attributes: Vec<(Key, AnyValue)>);
fn add_attributes<I, K, V>(&mut self, attributes: I)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be good to leave a comment explaining that this API is designed to take ownership, unlike Metric APIs which just need slice/ref only to attributes.

@cijothomas cijothomas merged commit de3147a into open-telemetry:main May 11, 2024
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants